package service

import (
	"guard/internal/app/oauth/models"
	"guard/internal/app/oauth/store"
)

type OAuthService interface {
	// Authorization 授权，返回html
	Authorization(username, clientId, grantType, redirectUri, codeChallenge, codeChallengeMethod string, scope []string) (client, state, scopes, uri string, err error)

	// Authentication 认证，重定向
	Authentication(state, username string, scope []string) (code, rUri string, err error)

	// Token 生成token
	Token(code, clientId, redirectUri, clientSecret, codeVerifier, requestUrl string) (rt models.ResultToken, err error)

	// RefreshToken 刷新token
	RefreshToken(clientId, clientSecret, refreshToken, requestUrl string) (rt models.ResultToken, err error)

	// ClientCredentials 客户端模式
	ClientCredentials(grantType, clientId, clientSecret, requestUrl string) (rt models.ResultToken, err error)

	// RevokeToken 注销token
	RevokeToken(clientId, clientSecret, token string) (bool, error)
}

type oauthServiceImpl struct {
	db store.OAuthStore
}

func NewOAuthService(s store.OAuthStore) OAuthService {
	return &oauthServiceImpl{
		db: s,
	}
}
